<?php
/**
 * Created by PhpStorm.
 * User: lijie
 * Date: 2018/10/3
 * Time: 13:46
 */
namespace app\api\model;

use think\Model;
use think\Db;
class YearcardUser extends Model{
    protected $dateFormat = 'Y-m-d H:i:s';
    protected $createTime = 'begin_time';
    protected $updateTime = 'end_time';

    /**
     * Notes:  查看年卡
     * Create Date: 2018/10/3
     * Create by :lijie
     */
    public function myYearCard($where,$pagenum=1,$listNum=10)
    {
        return $this->where($where)->order("create_time desc,end_time desc")->page($pagenum,$listNum)->select();
    }

    /**
     * Notes:  优惠券产品详情
     * Create Date: 2018/10/3
     * Create by :lijie
     */
    public function yearCardInfo($param)
    {
        return $this->where($param)->find();
    }


    /**
     * /
     * @author topqiang
     * @DateTime 2018-10-28T11:33:23+0800
     * @param    [type]                   $w [description]
     * @return   [type]                      [description]
     */
    public function updateOreder($w){
        file_put_contents("t1.txt",'进入方法体');
        $yearuser = $this->where($w)->find();
        $order = Db::name("yearcard")->where("id=".$yearuser['y_id'])->find();
        file_put_contents("t.txt",json_encode($yearuser).json_encode($order));

        $bill["begin_time"] = time();
        $bill["end_time"] = time()+$order['candate']*24*60*60;
        $bill["status"] = 1;
        $result = $this
                ->where($w)
                ->update($bill);
        file_put_contents("t.txt",json_encode($yearuser).json_encode($order));
        if($result){
            return true;
        }else{
            return false;
        }
    }
}